//
//  QQAPIHandler.m
//  BMHVideoMain
//
//  Created by 陈宪栋 on 2017/3/20.
//  Copyright © 2017年 陈宪栋. All rights reserved.
//

#import "QQApiHandler.h"
#import <UIKit/UIKit.h>
#import <TencentOpenAPI/QQApiInterface.h>


@implementation QQApiHandler
+ (void)qqFriendsShareWithUrl:(NSString *)url title:(NSString *)title description:(NSString *)description previewImageName:(NSString *)previewImageName {
    NSData *previewImageData = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:previewImageName]];
    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:description previewImageData:previewImageData];
    [imgObj setCflag:kQQAPICtrlFlagQQShare];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
    QQApiSendResultCode code = [QQApiInterface sendReq:req];
    [self handleSendResult:code];
}

+ (void)qqFriendsShareWithUrl:(NSString *)url title:(NSString *)title description:(NSString *)description previewImageURL:(NSString *)previewImageURL {
    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:description previewImageURL:[NSURL URLWithString:previewImageURL]];
    [imgObj setCflag:kQQAPICtrlFlagQQShare];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
    QQApiSendResultCode code = [QQApiInterface sendReq:req];
    [self handleSendResult:code];
}

+ (void)qqZoneShareWithUrl:(NSString *)url title:(NSString *)title description:(NSString *)description previewImageName:(NSString *)previewImageName {
    NSData *previewImageData = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:previewImageName]];
    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:description previewImageData:previewImageData];
    [imgObj setCflag:kQQAPICtrlFlagQZoneShareOnStart];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
    QQApiSendResultCode code = [QQApiInterface SendReqToQZone:req];
    [self handleSendResult:code];
}

+ (void)qqZoneShareWithUrl:(NSString *)url title:(NSString *)title description:(NSString *)description previewImageURL:(NSString *)previewImageURL {
    QQApiNewsObject *imgObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:description previewImageURL:[NSURL URLWithString:previewImageURL]];
    [imgObj setCflag:kQQAPICtrlFlagQZoneShareOnStart];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
    QQApiSendResultCode code = [QQApiInterface SendReqToQZone:req];
    [self handleSendResult:code];
}

+ (void)handleSendResult:(QQApiSendResultCode)sendResult {
    switch (sendResult) {
        case EQQAPIAPPNOTREGISTED: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"App未注册" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIMESSAGECONTENTINVALID:
        case EQQAPIMESSAGECONTENTNULL:
        case EQQAPIMESSAGETYPEINVALID: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIQQNOTINSTALLED: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未安装QQ" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIQQNOTSUPPORTAPI: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未安装QQ" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPISENDFAILD: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发送失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            
            break;
        }
        case EQQAPIVERSIONNEEDUPDATE: {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前QQ版本太低，需要更新" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [msgbox show];
            break;
        }
        default: {
            break;
        }
    }
}
@end
